package com.blockmeta.bbs.minemodule.adapter;

import android.content.Context;
import android.net.Uri;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.businesslibrary.business.UmengEvent;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.util.DeepLinkUtils;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.pojo.GoldShopPOJO;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;

import java.util.HashMap;
import java.util.List;

/**
 * @author AirThor
 * @date 2018/10/23.
 */
public class GoldShopAdapter extends BaseAdapter<GoldShopPOJO.ConversionBean,BaseViewHolder> {
    private Context mContext;
    public GoldShopAdapter(Context context, int layoutResId, @Nullable List<GoldShopPOJO.ConversionBean> data) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final GoldShopPOJO.ConversionBean item) {
        ImageView pic = helper.getView(R.id.iv_pic);
        if (!TextUtils.isEmpty(item.iconUrl)){
            Picasso.with(pic.getContext()).load(item.iconUrl).into(pic);
        }
        helper.setText(R.id.tv_cost,String.valueOf(item.price));
        helper.setText(R.id.tv_title,item.name);
        View view = helper.getView(R.id.container);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeepLinkUtils.jumpToTarget(mContext, Uri.parse(DeepLinkUtils.regexUri(item.link)));
                HashMap<String, String> map = new HashMap<>();
                map.put("object_ID",item.goodsId);
                UmengEvent.eventStatistics(mContext, Constant.U_MINE_goldshop_object,map);
            }
        });
    }
}
